package com.cn.kabalifemerchants.ui.user.activity;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.cn.kabalifemerchants.R;
import com.cn.kabalifemerchants.base.IBaseActivity;
import com.cn.kabalifemerchants.config.LoginHelper;
import com.cn.kabalifemerchants.ui.user.bean.HelpDetailsBean;
import com.cn.kabalifemerchants.ui.user.bean.HelpListBean;
import com.cn.kabalifemerchants.utils.RxToast;
import com.zzhoujay.richtext.ImageHolder;
import com.zzhoujay.richtext.RichText;

import butterknife.BindView;

/**
 * Created by 晓林 on 2020/9/10.
 * function: 富文本  帮助详情
 */
public class HelpDetailsActivity extends IBaseActivity<HelpListActivityView, HelpListActivityPresenter> implements HelpListActivityView {


    Bundle bundle;
    int id;
    @BindView(R.id.tv_details)
    TextView tvDetails;

    @Override
    protected HelpListActivityPresenter createPresenter() {
        return new HelpListActivityPresenter();
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_h5;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        bundle = getIntent().getExtras();
        id = bundle.getInt("id");
        setTitleBar("使用帮助");

        mPresenter.onHelpDetailsData(LoginHelper.getLonginData().getResult(), id);
    }

    @Override
    public void onReLoggedIn(String msg) {
        RxToast.error(msg);
        LoginHelper.againGoToLoginActivity(getMe());
    }

    @Override
    public void onError(String msg) {
        RxToast.error(msg);
    }

    @Override
    public Context _getContext() {
        return null;
    }

    @Override
    public void onHelpListSuccess(HelpListBean bean) {

    }

    @Override
    public void onHelpDetailsSuccess(HelpDetailsBean bean) {
        top_title.setText(bean.getResult().getTitle());
//        RichText.from(bean.getResult().getContent()).autoFix(false).showBorder(false).autoPlay(true).into(tvDetails);
        if (!TextUtils.isEmpty(bean.getResult().getContent())) {
            tvDetails.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
            RichText.fromHtml(bean.getResult().getContent()).autoFix(false).showBorder(false).autoPlay(true).scaleType(ImageHolder.ScaleType.fit_center) // 图片缩放方式
                    .size(ImageHolder.MATCH_PARENT, ImageHolder.WRAP_CONTENT).into(tvDetails);
        }
    }

}
